﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MadLibrary.Text;

namespace MadLibrary.Managing.Users
{
    /// <summary>
    /// Holds and manages simple user.
    /// </summary>
    public class User
    {
        /// <summary>
        /// Gets or sets users' username.
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// Gets or sets users' password.
        /// </summary>
        public string Password { get; set; }
        /// <summary>
        /// Gets or sets users' email.
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// Creates new User object instance and sets properties to their default values.
        /// </summary>
        public User()
        {
            this.UserName = "";
            this.Password = "";
            this.Email = "";
        }
        /// <summary>
        /// Creates new User object instance.
        /// </summary>
        /// <param name="UserName">Specifies users' username.</param>
        public User(string UserName)
        {
            this.UserName = UserName;
            this.Password = "";
            this.Email = "";
        }
        /// <summary>
        /// Creates new User object instance based on specified users' data.
        /// </summary>
        /// <param name="UserName">Specifies users' username.</param>
        /// <param name="Passwordrt">Specifies RandomText object instance for generating random password.</param>
        public User(string UserName, RandomText Passwordrt)
        {
            this.UserName = UserName;
            Passwordrt.Generate();
            this.Password = Passwordrt.GeneratedText;
            this.Email = "";
        }
        /// <summary>
        /// Creates new User object instance based on specified users' data.
        /// </summary>
        /// <param name="UserName">Specifies users' username.</param>
        /// <param name="Passwordrt">Specifies RandomText object instance for generating random password.</param>
        /// <param name="Email">Specifies users' email.</param>
        public User(string UserName, RandomText Passwordrt, string Email)
        {
            this.UserName = UserName;
            Passwordrt.Generate();
            this.Password = Passwordrt.GeneratedText;
            this.Email = Email;
        }
        /// <summary>
        /// Creates User object instance based on specified parameters.
        /// </summary>
        /// <param name="UserName">Specifies users' username.</param>
        /// <param name="Password">Specifies users' password.</param>
        public User(string UserName, string Password)
        {
            this.UserName = UserName;
            this.Password = Password;
            this.Email = "";
        }
        /// <summary>
        /// Creates User object instance based on specified parameters.
        /// </summary>
        /// <param name="UserName">Specifies users' username.</param>
        /// <param name="Password">Specifies users' password.</param>
        /// <param name="Email">Specifies users' email.</param>
        public User(string UserName, string Password, string Email)
        {
            this.UserName = UserName;
            this.Password = Password;
            this.Email = Email;
        }
        /// <summary>
        /// Serves as virtual base method for comparing two users.
        /// </summary>
        /// <param name="usr">Specifies instance of User object which should be compared.</param>
        /// <returns>True if are key data of users same, False if key data are not same.</returns>
        public virtual bool CompareUsers(User usr)
        {
            if (usr.UserName == this.UserName && usr.Password == this.Password && usr.Email == this.Email)
                return true;
            else return false;
        }
        /// <summary>
        /// Verifies this User object instances' key properties with data specified.
        /// </summary>
        /// <param name="Username">Specifies username for verification.</param>
        /// <param name="Password">Specifies password for verification.</param>
        /// <returns>True, if verification successful, or False if ti wasn't.</returns>
        public bool VerifyUser(string Username, string Password)
        {
            if (Username == this.UserName && Password == this.Password)
                return true;
            else return false;
        }
    }
}
